<template>
  <div style="padding: 10px; display: flex; flex-direction: column; height: 100%;">
    <el-form ref="cameraAiFormRef" :model="form" :rules="rules" label-width="80px" style="height: calc(100% - 100px); display: flex; flex-direction: column;">
        <el-form-item label="ai算法名称" prop="cameraAiName" label-width="100px">
          <el-input v-model="form.cameraAiName" show-word-limit maxlength="30" placeholder="请输入ai算法名称" />
        </el-form-item>
        <el-form-item label="备注" prop="remark" label-width="100px">
          <el-input v-model="form.remark" type="textarea" show-word-limit maxlength="120" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div style="height: 70px; display: flex; justify-content: center; align-items: end;">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="emit('close')">取 消</el-button>
      </div>
  </div>
</template>
<script lang="ts" setup>
import { cameraAiQuery, cameraAiForm } from '@/api/security/camera/camera-ai/types';
import { addcameraAi } from '@/api/security/camera/camera-ai';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const buttonLoading = ref(false);
const cameraAiFormRef = ref<ElFormInstance>();

const emit = defineEmits(['close', 'success']);

const initFormData: cameraAiForm = {
  cameraAiId: undefined,
  remark: undefined,
  cameraAiName: undefined
}
const data = reactive<PageData<cameraAiForm, cameraAiQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    cameraAiName: undefined,
    params: {
    }
  },
  rules: {
    cameraAiId: [
      { required: true, message: '主键不能为空', trigger: 'blur' }
    ],
    remark: [
      { required: true, message: '备注不能为空', trigger: 'blur' }
    ],
    cameraAiName: [
      { required: true, message: 'ai算法名称不能为空', trigger: 'blur' }
    ]
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 表单重置 */
const reset = () => {
  form.value = { ...initFormData };
  cameraAiFormRef.value?.resetFields();
}

/** 提交按钮 */
const submitForm = () => {
  cameraAiFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      await addcameraAi(form.value).finally(() => buttonLoading.value = false);
     
      proxy?.$modal.msgSuccess('操作成功');
      emit('close');
      reset();
      emit('success');
    }
  });
}
onMounted(() => {
});
</script>
<style lang="scss" scoped>

</style>
